﻿using Ayatta.Contract.Domain;

namespace Ayatta.Contract.Component
{
    public sealed class Condition<T> where T : IEntity
    {
        private int size;
        private int page;
        public int Size
        {
            get { return size; }
            set
            {
                if (value < 0 || size > 300)
                {
                    size = 300;
                }
                else
                {
                    size = value;
                }
            }
        }
        public int Page
        {
            get { return page; }
            set { page = value <= 0 ? 0 : value; }
        }
        public int BeginRow { get { return (Page - 1) * Size + 1; } }
        public int EndRow { get { return Page*Size; } }
        public dynamic Extra { get; set; }
        public T Conent { get; private set; }
        public Condition(T t): this(0, 0, t)
        {
           
        }
        public Condition(T t,dynamic extra): this(0, 0, t){
            Extra = extra;
        }
        public Condition(int size, T t, dynamic extra): this(size, 0, t)
        {
            Extra = extra;
        }
        public Condition(int size, T t): this(size, 0, t)
        {
            
        }
        public Condition(int size,int page,T t,dynamic extra=null)
        {
            Conent = t;
            Extra = extra;
            this.size = size;
            this.page = page;
        }
    }
}